# Definition for a binary tree node.
class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None


class Solution:
    def levelOrder(self, root: TreeNode):
        result = []
        level = self.getLevelNodes([root], result)
        while len(level) != 0:
            level = self.getLevelNodes(level, result)
        return result


    def getLevelNodes(self, arr, result):
        level_result = []
        if arr is None and len(arr) != 0:
            return []
        new_arr = []
        for node in arr:
            if node is None:
                continue
            level_result.append(node.val)
            new_arr.append(node.left)
            new_arr.append(node.right)
        if len(level_result):
            result.append(level_result)
        return new_arr


if __name__ == '__main__':
    so = Solution()
    root = TreeNode(1)
    root.left = TreeNode(0)
    r = so.levelOrder(root)
    print(r)
